package cn.good.yan.controller;

import cn.good.yan.myhandler.CustomerBlockHandler;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


/**
 * 演示：
 *     普通接口，演示 sentinel SentinelResource 自定义限流
 *      请求：http://localhost:8401/t4/testF?p2=ss&p1=25  都会进行限流，需要配置对应的限流规则
 *
 * @author shengren.yan
 * @create 2024-01-09
 */
@RestController
@RequestMapping("/t4")
@Slf4j
public class Test4Controller {

    @Value("${server.port}")
    private String serverPort;

    // 正常逻辑 - 执行 ， 熔断限流，方法在该CustomerBlockHandler下的handleException2方法
    @GetMapping("/testE")
    @SentinelResource(value = "testE",
            blockHandlerClass = CustomerBlockHandler.class, blockHandler = "handleException2")
    public String testD() {
        return "------testE -- 正常逻辑返回" ;
    }

    @GetMapping("/testF")
    @SentinelResource(value = "testF",
            blockHandlerClass = CustomerBlockHandler.class, blockHandler = "handleException3")
    public String testD(@RequestParam(value = "p1", required = false) String p1,
                        @RequestParam(value = "p2", required = false) String p2) {
        return "------testE -- 正常逻辑返回" ;
    }


}
